import React, { Component } from 'react';

class App extends Component {

  /* dom方式不可用 */
  // handleSubmit = ()=>{
  //   let ele = document.getElementById('inputFrom')
  //   console.log('提交',ele.value);
  // }

  state = {
    inputVal:'默认值',
  }
  handleSubmit = ()=>{
    console.log('提交',this.state.inputVal);
  }
  handleChange = (e)=>{
    console.log(e.target.value);
    this.setState((preState)=>{
      return {
        inputVal:e.target.value
      }
    })
  }
  render() {
    return (
      <div>
        {/* <input type="text" id='inputForm'/> */}
        <input type="text"
        value={this.state.inputVal}
        onChange={this.handleChange}
        />
        <button id="btn" onClick={this.handleSubmit}>提交</button>
      </div>
    );
  }
}

export default App;
